Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
mdast-zone
Advanced tools
MDAST utility to treat HTML comments as ranges or markers. Useful as a base for remark plugins.
npm:
npm install mdast-zone
mdast-zone is also available as an AMD, CommonJS, and globals module, uncompressed and compressed.
var zone = require('mdast-zone');
var remark = require('remark');
Callback invoked when a range
is found.
function onrun(start, nodes, end) {
return [
start.node,
{
'type': 'paragraph',
'children': [
{
'type': 'text',
'value': 'Bar'
}
]
},
end.node
];
}
Process a document.
var doc = remark().use(zone({
'name': 'foo',
'onrun': onrun
})).process(
'<!--foo start-->\n' +
'\n' +
'Foo\n' +
'\n' +
'<!--foo end-->\n'
);
Yields:
<!--foo start-->
Bar
<!--foo end-->
Note that mdast-zone is not a plugin by itself. It should be used by a remark plugin.
zone(options)
The goal of zone is two fold:
Configuration during remarks parse and/or stringification stage, using markers;
Transforming parts of a document without affecting other parts, which is not visible when rendering to HTML, using ranges (a starting marker, followed by nodes, and an ending marker).
The first is exposed by this plugin in the form of an HTML comment which sort-of looks like a self-closing, custom tag. The second by placing starting and ending tags, as siblings, in a parent.
options
name
(string
) — Type to look for;onparse
(Function
, optional)
— Callback invoked when a marker is found during parsing;onstringify
(Function
, optional)
— Callback invoked when a marker is found during stringification;onrun
(Function, optional)
— Callback invoked when a range is found during transformation.Function
, which should be passed to remark.use()
.
function onparse(marker)
function onstringify(marker)
When passing name: "foo"
and onparse: console.log.bind(console)
to
zone()
, comments in the form of <!--foo bar="baz" qux-->
are detected
and onparse
is invoked during the parsing phase.
An onstringify
method could (instead, or both) be passed to zone()
,
which would be invoked with the same marker
but during the
stringification phase.
marker
(Marker
).function onrun(start, nodes, end, scope)
Invoked during the transformation phase with markers which determine
a range: two markers, the first start
and the last end
, and the
content inside.
start
(Marker
) — Start of range;
nodes
(Array.<Node>
) — Nodes between start
and end
;
end
(Marker
) — End of range.
scope
(Object
):
parent
(Node
) — Parent of the range;start
(number
) — Index of start
in parent
;end
(number
) — Index of end
in parent
.Array.<Node>?
— Zero or more nodes to replace the range (including
start
and end
s markers) with.
FAQs
mdast utility to treat HTML comments as ranges or markers
We found that mdast-zone demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.